<template>
	<view class="tab">
		<view class="tab-field">
			<view class="tab-field-pwd">
				<van-field
					label="解封账户"
					type="number"
					placeholder="请输入需要解封的账号"
					clearable
					:value="from.number"
					:border="false"
					@change="cNumber"
				/>
			</view>
		
			<van-cell-group>
			   <van-field
					label="二级密码"
					type="password"
					placeholder="请输入二级密码"
					clearable
					:value="from.payPassword"
					@change="cPasswordT"
			  />
			   <van-field
					label="身份证号"
					placeholder="请输入您的身份证号码"
					clearable
					:value="from.idCards"
					:border="false"
					@change="cIdCards"
			  />
			</van-cell-group>
		</view>
		<view class="tab-btn-wrap">
			<button class="base-btn" @tap="onSubmit">提交</button>
		</view>
	</view>
</template>

<script>
import * as reg from '../../../common/utils/reg.js';
import { mapGetters } from 'vuex';
export default {
	data() {
		return {
			loading: false,
			from: {
				number: '',
				payPassword: '',
				idCards: ''
			}
		};
	},
	computed: {
		...mapGetters({
			userInfo: 'getUserInfo'
		})
	},
	methods: {
		onSubmit () {
			if (this.loading) return
			const regSubmit = reg.regSubmit(this.from)
			if (regSubmit) {
				uni.showToast({
					title: regSubmit, 
					icon: 'none'
				});
				return
			}
			uni.showLoading({ title: '' });
			this.loading = true
			this.$http.myUnban({
				number: this.from.number,
				pwdtwo: this.from.payPassword,
				idcode: this.from.idCards
			}).then(res => {
				const data = res.data
				this.loading = false
				if (data.success) {
					uni.showToast({
						title: '申请成功！'
					});
					this.onClear()
					return
				}
				uni.showToast({
					title: data.errMsg,
					icon: 'none'
				})
			}).catch(err => {
				this.loading = false
			})
		},
		onClear () {
			this.$set(this.from, 'number', '')
			this.$set(this.from, 'payPassword', '')
			this.$set(this.from, 'idCards', '')
		},
		cNumber(e) {
			this.from.number = e.detail
		},
		cPasswordT(e) {
			this.from.payPassword = e.detail
		},
		cIdCards(e) {
			this.from.idCards = e.detail
		}
	}
};
</script>

<style lang="scss" scoped>
	.tab {
		padding: 40upx 0;
		&-field {
			margin-bottom: 40upx;
			&-pwd{margin-bottom: 20upx;}
		}
		&-btn-wrap {
			padding: 40upx 60upx;
		}
	}
</style>
